<?php

namespace App\Http\Controllers\Kms\Backend\App;

use App\Http\Controllers\Kms\Backend\BackendBaseController;
use App\Http\Validate\Kms\Clients\ClientsValidate;
use App\Service\Kms\App\ClientService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class ClientController extends BackendBaseController
{
    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function list(Request $request): JsonResponse
    {
        $params = ClientsValidate::backendListValidate($request->all());
        return $this->success(ClientService::backendList($params));
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function add(Request $request): JsonResponse
    {
        $params = ClientsValidate::addValidate($request->all());
        ClientService::addClient($params);
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function update(Request $request): JsonResponse
    {
        $params = ClientsValidate::updateValidate($request->all());
        ClientService::updateClient($params);
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function status(Request $request): JsonResponse
    {
        $params = ClientsValidate::statusValidate($request->all());
        ClientService::statusClient($params);
        return $this->success();
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ValidationException
     */
    public function delete(Request $request): JsonResponse
    {
        $params = ClientsValidate::deleteValidate($request->all());
        ClientService::deleteClient($params);
        return $this->success();
    }
}
